//
//  FindTableViewController.m
//  MyItem
//
//  Created by admin on 15/12/23.
//  Copyright © 2015年 admin. All rights reserved.
//

#import "FindTableViewController.h"
#import "FindListModel.h"
#import "FindCell.h"
#import "StoryTableViewController.h"
@interface FindTableViewController ()




@end

@implementation FindTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"发现";
    
    self.tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    //注册单元格
    [self.tableView registerNib:[UINib nibWithNibName:@"FindCell" bundle:nil] forCellReuseIdentifier:@"findCell"];
    
    
    [self loadData];
}

-(void)loadData
{
    NSDictionary *parms = @{
                            @"sign": @"uyc9bk_Ojmg-rW740CIGgA",
                            @"d_model": @"iPhone4,1",
                            @"networkType": @"wifi",
                            @"adid": @"5BAD0863-7735-475F-B800-07AF74862C1F",
                            @"st": @"1451463814411",
                            @"body": @"{\"geo\":{\"lng\":\"0.000000\",\"lat\":\"0.000000\"},\"poz\":{\"city\":\"浙江:杭州\",\"time\":1451460047413},\"deviceId\":\"a1e609be3483012e09542a204a2a6dfd05c016be\"}",
                            @"osVersion": @"7.1.2",
                            @"d_brand": @"apple",
                            @"client": @"apple",
                            @"screen": @"640*960",
                            @"sv": @"1",
                            @"area": @"15_1213_3038_0",
                            @"build": @"35977",
                            @"uuid": @"hjudwgohxzVu96krv/T6Hg==",
                            @"clientVersion": @"4.4.3",
                            @"openudid": @"a1e609be3483012e09542a204a2a6dfd05c016be",
                            @"partner": @"apple"
                            };
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager POST:@"http://portal.m.jd.com/client.action?functionId=jdDiscoveryFloor" parameters:parms success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
        
//        NSLog(@"%@",responseObject);
        NSArray *floorList = responseObject[@"floorList"];
        NSMutableArray *modelArray = [NSMutableArray array];
        for (NSDictionary *dic in floorList)
        {
            FindListModel *model = [[FindListModel alloc]initWithDataDic:dic];
            [modelArray addObject:model];
        }
        _dataArray = modelArray;

        [self.tableView reloadData];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source
//cell高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}
//组数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 4;
}

//单元格个数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 2;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    FindCell *cell = [tableView dequeueReusableCellWithIdentifier:@"findCell" forIndexPath:indexPath];

    cell.model = _dataArray[indexPath.section*2 + indexPath.row];
    return cell;
}

//选中单元格
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) //故事
    {
        StoryTableViewController *storyVC = [[StoryTableViewController alloc]init];
        
        [self.navigationController pushViewController:storyVC animated:YES];
    }
    
    
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
